package com.yinhe.module.yzx.tb;

import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.domain.entity.SysUser;
import com.yinhe.common.core.domain.model.LoginUser;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.DateUtils;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhContent;
import com.yinhe.system.domain.YhFoundations;
import com.yinhe.system.service.IYhContentService;
import com.yinhe.system.service.IYhFoundationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/yzx/tb/foundations")
public class YzxTechnicalbasisController extends BaseController
{
    @Autowired
    private IYhFoundationsService yhFoundationsService;

    /**
     * 查询技术基础列表
     */
    @PreAuthorize("@ss.hasPermi('yzx:tb:foundations:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhFoundations yhFoundations)
    {
        startPage();
        List<YhFoundations> list = yhFoundationsService.selectYhFoundationsList(yhFoundations);
        return getDataTable(list);
    }

    /**
     * 导出技术基础列表
     */
    @PreAuthorize("@ss.hasPermi('yzx:tb:foundations:export')")
    @Log(title = "技术基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhFoundations yhFoundations)
    {
        List<YhFoundations> list = yhFoundationsService.selectYhFoundationsList(yhFoundations);
        ExcelUtil<YhFoundations> util = new ExcelUtil<YhFoundations>(YhFoundations.class);
        util.exportExcel(response, list, "科学研究数据");
    }

    /**
     * 获取技术基础详细信息
     */
    //@PreAuthorize("@ss.hasPermi('yzx:tb:foundations:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhFoundationsService.selectYhFoundationsById(id));
    }

    /**
     * 新增技术基础
     */
    @PreAuthorize("@ss.hasPermi('yzx:tb:foundations:add')")
    @Log(title = "技术基础", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhFoundations yhFoundations)
    {

        // 获取当前登录用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getUser();
        // 存入userId和deptId，做数据权限
        yhFoundations.setUserId(sysUser.getUserId());
        yhFoundations.setDeptId(sysUser.getDeptId());

        yhFoundations.setReleaseTime(DateUtils.getNowDate());
        System.out.println(yhFoundations.getTopicCategory()+"getTopicCategory");

        return toAjax(yhFoundationsService.insertYhFoundations(yhFoundations));
    }

    /**
     * 修改技术基础
     */
    @PreAuthorize("@ss.hasPermi('yzx:tb:foundations:edit')")
    @Log(title = "技术基础", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhFoundations yhFoundations)
    {
        return toAjax(yhFoundationsService.updateYhFoundations(yhFoundations));
    }

    /**
     * 删除技术基础
     */
    @PreAuthorize("@ss.hasPermi('yzx:tb:foundations:remove')")
    @Log(title = "技术基础", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhFoundationsService.deleteYhFoundationsByIds(ids));
    }
}
